package com.vx.vxbug.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.vx.vxbug.entities.Program;
import com.vx.vxbug.services.ProgramService;
import com.vx.vxbug.services.UserService;

@Controller
public class ProgramController {
	@Autowired
	private ProgramService pS;
	@Autowired
	private UserService uS;

	@RequestMapping(value = { "/addProgram" }, method = RequestMethod.GET)
	public String addProgramGet(Model model) {
		return "addProgram";
	}

	@RequestMapping(value = { "/addProgram" }, method = RequestMethod.POST)
	public String addProgramPost(@ModelAttribute(value = "name") String name, @ModelAttribute(value = "desc") String desc,
			@ModelAttribute(value = "userLogin") String userLogin, Model model) {
		int userId = uS.getUserByLogin(userLogin).getId();
		Program b = new Program(name, desc, userId);
		pS.addProgram(b);
		return "redirect:";
	}

}
